package codebot.processor.languages;

import codebot.elector.Candidate;
import codebot.processor.IScreen;
import codebot.processor.logic.Score;

/**
 * Superclass for specific programming languages
 */
public abstract class Lang {
	protected static int DEPTH = 0;

	/**
	 * Languages and language families extend one another and form a tree. The
	 * depth in this tree influences the scores languages get when compared.
	 * 
	 * @return The depth of the instantiated language in the tree.
	 */
	public final int getDepth() {
		return DEPTH;
	}

	/**
	 * Specific process method inherited by every language processor
	 * 
	 * @param screen
	 * @param code
	 * @param s
	 * @param e
	 */
	public abstract void processSpecificSyntax(final IScreen screen,
			final String code, final int s, final int e);

	/**
	 * Factory function for specific syntax processors, based on scores
	 * 
	 * @param s
	 * @return
	 */
	public final static Lang getSpecificSyntaxProcessor(final Score s) {
		return getSpecificSyntaxProcessor(s.getLanguage());
	}

	/**
	 * General factory function for specific syntax processors
	 * 
	 * @param language
	 * @return
	 */
	public final static Lang getSpecificSyntaxProcessor(final Candidate language) {

		if (language == Score.sCFamily) {
			return new CFamily();
		} else if (language == Score.sJava) {// TODO implement equals & factory
			return new Java();
		} else if (language == Score.sPhp) {
			return new Php();
		} else if (language == Score.sXml) {
			return new Xml();
		} else if (language == Score.sJavascript) {
			return new Javascript();
		}

		return new NullLang();
	}

	/**
	 * To find out the name of the language
	 */
	public abstract String toString();
}
